package com.yuan.algorithms.arithmetic_1;

import java.util.Scanner;


class TreeNode{
	String data;
	TreeNode left;
	TreeNode right;
}
/*
ABDECFG
DBEAFCG
DEBFGCA
*/
public class BinaryTree {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String qS=sc.next();
		String zS=sc.next();
		TreeNode head=createBinaryTree(qS,zS);
		postorderTraversal(head);
		System.out.println();
	}
	public static TreeNode createBinaryTree(String qS,String zS){
		TreeNode currNode=null;
		//找出根节点
		String gen=qS.substring(0,1);
		currNode=new TreeNode();
		currNode.data=gen;
		if(qS.length()==1) return currNode;
		//找出根节点在中序中的位置
		int k=zS.indexOf(gen);
		String zqS=qS.substring(1,k+1);
		String zzS=zS.substring(0,k);
		currNode.left=createBinaryTree(zqS,zzS);
		String yqS=qS.substring(k+1);
		String yzS=zS.substring(k+1);
		currNode.right=createBinaryTree(yqS,yzS);
		return currNode;
	}
	public static void postorderTraversal(TreeNode currNode){
		if(currNode!=null){
			postorderTraversal(currNode.left);
			postorderTraversal(currNode.right);
			System.out.print(currNode.data+" ");
		}
	}
}
